package com.zhzh.sc.demo.juc.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ThreadTest extends Thread {
    private String name;

    public ThreadTest(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println("hello, " + name);
    }


    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        final Random random = new Random();
        final List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 100000; i++) {
            Thread thread = new Thread() {
                public void run() {
                    list.add(random.nextInt());
                }
            };
            thread.start();
            thread.join();
        }
        System.out.println("spend: " + (System.currentTimeMillis() - start));
        System.out.println("list size=" + list.size());
    }
}
